package www.reviewW.data;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

public class ModeData implements Serializable {
    private String id; //栏标识
    private String title; //栏标题
    private List<Knowledge> knowledges = new ArrayList<>(); //知识点条目

    public ModeData(String title) {
        this.title = title;
        this.id = UUID.randomUUID().toString();
    }

    //添加知识点
    public void addKnowledge(String title){
        Knowledge knowledge = new Knowledge(title);
        knowledges.add(knowledge);
    }
    public void addKnowledge(String title,String content){
        Knowledge knowledge = new Knowledge(title,content);
        knowledges.add(knowledge);
    }
    //删除知识点，通过 知识点标识
    public void deleteKnowledge(String id){
        for(Knowledge knowledge:knowledges){
            if(knowledge.getId().equals(id)){
                knowledges.remove(knowledge);
                return;
            }
        }
    }
    //获取一个随机知识点用来复习
    public Knowledge RandomKnowledge(){
        int i = knowledges.size();
        i = (int)(Math.random()*i);
        return knowledges.get(i);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public List<Knowledge> getKnowledges() {
        return knowledges;
    }

    public void setKnowledges(List<Knowledge> knowledges) {
        this.knowledges = knowledges;
    }
}
